#include "stdafx.h"
#include "jglobals.h"
#include <mutex>

std::unordered_map<std::wstring,boost::any> JGlobals::s_global;

static std::mutex s_global_mutex;
void JGlobals::SetAny(const std::wstring &key, boost::any &value)
{
    std::lock_guard<std::mutex> guard(s_global_mutex);
    s_global[key]=value;
}

bool JGlobals::GetAny(const std::wstring &key, boost::any &value)
{
    std::lock_guard<std::mutex> guard(s_global_mutex);
    auto ptr=s_global.find(key);
    if(ptr!=s_global.end())
    {
        value=ptr->second;
        return true;
    }
    return false;
}

bool JGlobals::HasKey(const std::wstring &key)
{
    std::lock_guard<std::mutex> guard(s_global_mutex);
    auto ptr=s_global.find(key);
    if(ptr!=s_global.end())
    {
        return true;
    }
    return false;
}

bool JGlobals::Erase(const std::wstring &key)
{
    std::lock_guard<std::mutex> guard(s_global_mutex);
    auto ptr=s_global.find(key);
    if(ptr!=s_global.end())
    {
        s_global.erase(ptr);
        return true;
    }
    return false;
}
